<template>
	<view class="">
	</view>
</template>

<script>
	import {
		Base64
	} from "js-base64";

	export default {
		methods: {
			login(loginToken) {
				this.$http({
					url: '/loginToken',
					header: {
						'loginToken': loginToken
					},
					method: 'POST'
				}).then((loginInfo) => {
					console.log("登录成功,自动跳转到聊天页面...")
					uni.setStorageSync("loginInfo", loginInfo);
					uni.setStorageSync("userName", loginInfo.userName);
					// 调用App.vue的初始化方法
					getApp().$vm.init()
					// 跳转到聊天页面
					uni.switchTab({
						url: "/pages/chat/chat"
					})
				})
			}
		},
		onLoad(option) {
			if (option.param) {
				let decode = Base64.decode(option.param);
				let param = JSON.parse(decode);
				if (param.miniToken) {
					this.login(param.miniToken);
				}
			}
			webUni.postMessage({});
		}
	}
</script>